package org.sport.presenter;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.sport.logic.Logic_SportActivity;
import org.sport.model.jsonModel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;


/**
 * Created by zehong
 *
 * 主要用于对接运动圈活动信息
 * 分为全部活动，我参与的，我发布的
 *
 */

@Controller
public class Interface_SportActivity {


    @Autowired
    Logic_SportActivity logicForSpoAct;


    /**
     * 功能：创建活动
     * json参数：创建人，活动的各种信息
     * 返回：创建结果
     */
    @RequestMapping(value = "/3/createActivity", method = RequestMethod.POST)
    public void createActivity(@RequestBody Json_3_createActivity json_3_createActivity
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("Interface_createActivity");
        Json_3_createActivity create=logicForSpoAct.createActivity(json_3_createActivity);
        try {

            response.getWriter().print(JSONObject.fromObject(create).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }




    //*********************活动*********************


    /**
     * 功能：活动--返回所有的活动
     * json参数：无
     * 返回：所有活动
     */
    @RequestMapping(value = "/3/activity_all", method = RequestMethod.POST)
    public void activity_all(@RequestBody Json_3_activity_all json_3_activity_all
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("Interface_activity_all");
        ArrayList<Json_3_activity_all> all=logicForSpoAct.activity_all(json_3_activity_all);
        try {

            response.getWriter().print(JSONArray.fromObject(all).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * 功能：活动--返回一个的活动
     * json参数：活动ID
     * 返回：一个活动
     */
    @RequestMapping(value = "/3/activity_single", method = RequestMethod.POST)
    public void activity_single(@RequestBody Json_3_activity_single json_3_activity_single
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("Interface_activity_single");
        Json_3_activity_single single=logicForSpoAct.activity_single(json_3_activity_single);
        try {

            response.getWriter().print(JSONObject.fromObject(single).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 功能：活动--获取某个活动的所有评论
     * json参数：活动ID
     * 返回：一个活动所有评论
     */
    @RequestMapping(value = "/3/activity_comments_all", method = RequestMethod.POST)
    public void activity_comments_all(@RequestBody Json_3_activity_comments_all json_3_activity_comments_all
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {

        System.out.println("Interface_activity_comments_all");

        ArrayList<Json_3_activity_comments_all> all=logicForSpoAct.activity_comments_all(json_3_activity_comments_all);
        try {

            response.getWriter().print(JSONArray.fromObject(all).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * 功能：活动--在某个活动下评论
     * json参数：用户电话号码，是否评论活动或别人，评论ID，评论内容
     * 返回：添加评论结果
     */
    @RequestMapping(value = "/3/activity_comments_create", method = RequestMethod.POST)
    public void activity_comments_create(@RequestBody Json_3_activity_comments_create json_3_activity_comments_create
            , HttpServletRequest request
            , HttpServletResponse response
    ) {

        System.out.println("Interface_activity_comments_create");

        json_3_activity_comments_create = logicForSpoAct.activity_comments_create(json_3_activity_comments_create);
        try {

            response.getWriter().print(JSONObject.fromObject(json_3_activity_comments_create).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


        /**
         * 功能：活动--申请参加某个活动
         * json参数：用户电话号码，活动ID
         * 返回：申请结果
         */
        @RequestMapping(value = "/3/activity_join", method = RequestMethod.POST)
        public void activity_join(@RequestBody Json_3_activity_join json_3_activity_join
                , HttpServletRequest request
                , HttpServletResponse response
        )
        {

            System.out.println("Interface_activity_join");

            json_3_activity_join=logicForSpoAct.activity_join(json_3_activity_join);
            try {

                response.getWriter().print(JSONObject.fromObject(json_3_activity_join).toString());
            } catch (IOException e) {
                e.printStackTrace();
            }
    }




    //*********************我参与的*********************



    /**
     * 功能：我参与的--返回我参与的所有的活动
     * json参数：电话号码
     * 返回：我参与的所有的活动
     */
    @RequestMapping(value = "/3/join_all", method = RequestMethod.POST)
    public void join_all(@RequestBody Json_3_join_all json_3_join_all
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("Interface_join_all");
        ArrayList<Json_3_join_all> all=logicForSpoAct.join_all(json_3_join_all);
        try {

            response.getWriter().print(JSONArray.fromObject(all).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * 功能：我参与的--返回我参与的其中一个活动详情
     * json参数：电话号码，活动ID
     * 返回：返回我参与的其中一个活动详情
     */
    @RequestMapping(value = "/3/join_single", method = RequestMethod.POST)
    public void join_single(@RequestBody Json_3_join_single json_3_join_single
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("Interface_join_single");
        Json_3_join_single single=logicForSpoAct.join_single(json_3_join_single);
        try {

            response.getWriter().print(JSONObject.fromObject(single).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 功能：我参与的-获取我参与的某个活动所有评论
     * json参数：电话号码，活动ID，是不是评论活动或他人
     * 返回：我参与的某个活动所有评论
     */
    @RequestMapping(value = "/3/join_comments_all", method = RequestMethod.POST)
    public void join_comments_all(@RequestBody Json_3_join_comments_all json_3_join_comments_all
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {

        System.out.println("Interface_join_comments_all");

        ArrayList<Json_3_join_comments_all> all=logicForSpoAct.join_comments_all(json_3_join_comments_all);
        try {

            response.getWriter().print(JSONArray.fromObject(all).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * 功能：我参与的-在我参与的某个活动下进行评论
     * json参数：用户电话号码，活动id，是否评论活动或别人，评论内容
     * 返回：添加评论结果
     */
    @RequestMapping(value = "/3/join_comments_create", method = RequestMethod.POST)
    public void join_comments_create(@RequestBody Json_3_join_comments_create json_3_join_comments_create
            , HttpServletRequest request
            , HttpServletResponse response
    ) {

        System.out.println("Interface_join_comments_create");

        json_3_join_comments_create = logicForSpoAct.join_comments_create(json_3_join_comments_create);
        try {

            response.getWriter().print(JSONObject.fromObject(json_3_join_comments_create).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * 功能：我参与的-退出我参与的某个活动
     * json参数：用户电话号码，活动ID
     * 返回：退出结果
     */
    @RequestMapping(value = "/3/join_signout", method = RequestMethod.POST)
    public void join_signout(@RequestBody Json_3_join_signout json_3_join_signout
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {

        System.out.println("Interface_activity_join");

        json_3_join_signout=logicForSpoAct.join_signout(json_3_join_signout);
        try {

            response.getWriter().print(JSONObject.fromObject(json_3_join_signout).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }







    //*********************我发布的*********************


    /**
     * 功能：我发布的--返回我发布的所有的活动
     * json参数：用户电话号码
     * 返回：我发布的所有的活动
     */
    @RequestMapping(value = "/3/release_all", method = RequestMethod.POST)
    public void release_all(@RequestBody Json_3_release_all json_3_release_all
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("Interface_release_all");
        ArrayList<Json_3_release_all> all=logicForSpoAct.release_all(json_3_release_all);
        try {

            response.getWriter().print(JSONArray.fromObject(all).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * 功能：我发布的--返回我发布的其中一个活动详情
     * json参数：用户电话号码，活动ID
     * 返回：我发布的其中一个活动详情
     */
    @RequestMapping(value = "/3/release_single", method = RequestMethod.POST)
    public void release_single(@RequestBody Json_3_release_single json_3_release_single
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("Interface_release_single");
        Json_3_release_single single=logicForSpoAct.release_single(json_3_release_single);
        try {

            response.getWriter().print(JSONObject.fromObject(single).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 功能：我参与的-获取我发布的某个活动所有评论
     * json参数：用户电话号码，活动ID，是不是评论活动或他人
     * 返回：我发布的某个活动所有评论
     */
    @RequestMapping(value = "/3/release_comments_all", method = RequestMethod.POST)
    public void release_comments_all(@RequestBody Json_3_release_comments_all json_3_release_comments_all
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {

        System.out.println("Interface_release_comments_all");

        ArrayList<Json_3_release_comments_all> all=logicForSpoAct.release_comments_all(json_3_release_comments_all);
        try {

            response.getWriter().print(JSONArray.fromObject(all).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * 功能：我发布的-在我发布的某个活动下进行评论
     * json参数：用户电话号码，活动id，是否评论活动或别人，评论内容
     * 返回：在我发布的某个活动下进行评论
     */
    @RequestMapping(value = "/3/release_comments_create", method = RequestMethod.POST)
    public void release_comments_create(@RequestBody Json_3_release_comments_create json_3_release_comments_create
            , HttpServletRequest request
            , HttpServletResponse response
    ) {

        System.out.println("Interface_release_comments_create");

        json_3_release_comments_create = logicForSpoAct.release_comments_create(json_3_release_comments_create);
        try {

            response.getWriter().print(JSONObject.fromObject(json_3_release_comments_create).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * 功能：我发布的-取消我发布的某个活动
     * json参数：用户电话号码，活动ID
     * 返回：取消活动结果
     */
    @RequestMapping(value = "/3/release_cancel", method = RequestMethod.POST)
    public void release_cancel(@RequestBody Json_3_release_cancel json_3_release_cancel
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {

        System.out.println("Interface_release_cancel");

        json_3_release_cancel=logicForSpoAct.release_cancel(json_3_release_cancel);
        try {

            response.getWriter().print(JSONObject.fromObject(json_3_release_cancel).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
